<?php
/**
 * 新闻
 * User: Lin Hui
 * Date: 2017/5/22
 * Time: 11:44
 */

namespace Mobile\Controller;


use Common\Model\ArticleModel;

class NewsController extends BaseController
{
    /**
     * 企业新闻
     */
    public function company()
    {
        list($list, $page) = (new ArticleModel())->getArticleByCategory(2, 6);
        foreach($list as $key => $item) {
            $list[$key]['title'] = more_hidden($item['title'], 0, 25);
        }
        $page->show();
        $this->assign('page', $page);
        $this->assign('list', $list);
        $this->display();
    }

    /**
     * 媒体新闻
     */
    public function media()
    {
        list($list, $page) = (new ArticleModel())->getArticleByCategory(3, 6);
        foreach($list as $key => $item) {
            $list[$key]['title'] = more_hidden($item['title'], 0, 25);
        }
        $page->show();
        $this->assign('page', $page);
        $this->assign('list', $list);
        $this->display();
    }
    /**
     * 金融资讯
     */
    public function finance()
    {
        list($list, $page) = (new ArticleModel())->getArticleByCategory(C('ARTICLE.category')['finance'], 6);
        $page->show();
        $this->assign('page', $page);
        $this->assign('list', $list);
        $this->display();
    }

    /**
     * 视频新闻
     */
    public function video()
    {
        list($list, $page) = (new ArticleModel())->getArticleByCategory(1, 6);
        foreach($list as $key => $item) {
            $list[$key]['title'] = more_hidden($item['title'], 0, 25);
        }
        $page->show();
        $this->assign('page', $page);
        $this->assign('list', $list);
        $this->display();
    }

    /**
     * 文章详情页
     */
    public function detail()
    {
        $model = new ArticleModel();
        $info = $model->getInfo(I('id', 0, 'intval'));
        if($info){
            $cat = C('ARTICLE.category');
            if($cat[I('cat')]) {
                $this->assign('up', $model->getUpArticle($cat[I('cat')], $info['create_time']));
                $this->assign('down', $model->getDownArticle($cat[I('cat')], $info['create_time']));
            }
            $model->addClick($info['article_id']);
            $this->assign('info', $info);
        }
        $this->display();
    }

    /**
     * 搜索
     */
    public function search()
    {
        $map = [];
        if($keywords = I('keywords')) {
            $map['title'] = ['like', "%$keywords%"];
        }
        $model = new ArticleModel();
        list($list, $page) = $model->getArticleByMap($map, 6);
        foreach($list as $key => $item) {
            $list[$key]['title'] = wrapWord(more_hidden($item['title'], 0, 25), $keywords, ['<strong class="searchText">', '</strong>']);
        }
        $page->show();
        $this->assign('page', $page);
        $this->assign('list', $list);
        $this->display();
    }

}